package com.jml.nio;

import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class ChanelApiTransferAPI {

	public void fun21() throws IOException {
		FileChannel inChannel = FileChannel.open(Paths.get("1.jpg"),StandardOpenOption.READ);
		FileChannel outChannel = FileChannel.open(Paths.get("4.jpg"),StandardOpenOption.READ,StandardOpenOption.WRITE,StandardOpenOption.CREATE_NEW);

		//表示用inchannel到outChannel,范围是从inChannel的0到inChannel的结尾
		long l = inChannel.transferTo(0,inChannel.size(),outChannel);

		inChannel.close();
		outChannel.close();
	}

	public void fun2() throws IOException {
		FileChannel inChannel = FileChannel.open(Paths.get("1.jpg"),StandardOpenOption.READ);
		FileChannel outChannel = FileChannel.open(Paths.get("4.jpg"),StandardOpenOption.READ,StandardOpenOption.WRITE,StandardOpenOption.CREATE_NEW);

		//表示用outchannel来自inchanel，范围是从inChannel的0到inChannel的结尾
		outChannel.transferFrom(inChannel,0,inChannel.size());

		inChannel.close();
		outChannel.close();
	}

}
